package com.itheima.blog.admin.controller;

import com.itheima.blog.admin.aop.MyLog;
import com.itheima.blog.admin.dto.TagReqDto;
import com.itheima.blog.admin.entity.Tag;
import com.itheima.blog.admin.service.TagService;
import com.itheima.common.domain.PageResDto;
import com.itheima.common.domain.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标签controller
 * */
@RequestMapping("/tag")
@RestController
public class TagController {

    @Autowired
    private TagService tagService;

    @ApiOperation(value = "feign获取标签列表", notes = "feign获取标签列表", response = String.class)
    @PostMapping("/getList")
    public List<Tag> getList() {
        return tagService.getList();
    }

    @ApiOperation(value = "feign根据标签IDs获取标签名列表", notes = "feign根据标签IDs获取标签名列表")
    @GetMapping("/listWithIds")
    public List<Tag> listWithIds(@RequestParam List<Integer> tagIds) {
        return tagService.listByIds(tagIds);
    }

    @ApiOperation(value = "分页获取标签列表", notes = "获取标签列表", response = String.class)
    @PostMapping("/getPageList")
    public PageResDto<Tag> getPageList(@RequestBody TagReqDto tagVO) {
        return tagService.getPageList(tagVO);
    }

    @MyLog(value = "增加标签")
    @ApiOperation(value = "增加标签", notes = "增加标签", response = String.class)
    @PostMapping("/add")
    public R<Integer> add(@RequestBody TagReqDto tagVO) {
        return R.ok(tagService.addTag(tagVO));
    }

    @MyLog(value = "编辑标签")
    @ApiOperation(value = "编辑标签", notes = "编辑标签", response = String.class)
    @PostMapping("/edit")
    public R<Boolean> edit(@RequestBody TagReqDto tagVO) {
        return R.ok(tagService.editTag(tagVO));
    }

    @MyLog(value = "删除标签")
    @ApiOperation(value = "删除标签", notes = "删除标签", response = String.class)
    @PostMapping("/delete")
    public R<Boolean> delete(@RequestBody TagReqDto tagVo) {
        return R.ok(tagService.deleteTag(tagVo));
    }

    @MyLog(value = "批量删除标签")
    @ApiOperation(value = "批量删除标签", notes = "批量删除标签", response = String.class)
    @PostMapping("/deleteBatch")
    public R<Boolean> delete(@RequestBody List<TagReqDto> tagVoList) {
        return R.ok(tagService.deleteBatchTag(tagVoList));
    }

}
